import requests,json,time
from urllib import parse
p_token= ''#push+
content=""#通知结果
Cookie = ""#抓取的cookies
headers = {"Host": "farm.api.ddxq.mobi",
        "Connection": "keep-alive",
        "Accept": "*/*",
        "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN",
        "Referer": "https://game.m.ddxq.mobi/index.html",
        "Origin": "https://game.m.ddxq.mobi",
        "Cookie": Cookie
        }

headers2 = {"Host": "farm.api.ddxq.mobi",
        "Connection": "keep-alive",
        "Accept": "*/*",
        "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN",
        "Referer": "https://orchard-m.ddxq.mobi/?is_nav_hide=true&isResetAudio=true&s=mine_orchard",
        "Origin": "https://orchard-m.ddxq.mobi",
        "Cookie": Cookie,
        "DDMC-GAME-TID": "2"
        }


def 叮咚签到():
    url = 'https://sunquan.api.ddxq.mobi/api/v2/user/signin/'
    headers = {"Host": "sunquan.api.ddxq.mobi",
               "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
               "Connection": "keep-alive",
               "Accept-Language": "zh-cn",
               "Referer": "https://activity.m.ddxq.mobi/",
               "Content-Length": "166",
               "Content-Type": "application/x-www-form-urlencoded",
               "Origin": "https://activity.m.ddxq.mobi",
               "Accept-Encoding": "gzip, deflate, br",
               "Accept": "*/*",
               "Cookie": Cookie

               }
    data = "api_version=9.7.3&app_version=1.0.0&app_client_id=3&station_id=60e26f9abd8d8c0001eca0e8&native_version=9.40.0&city_number=1802&latitude=24.608563&longitude=118.103879"
    global content
    response = requests.post(url=url, data=data, headers=headers)

    if response.text.find('point') !=-1:
        aaa = json.loads(response.text)
        print("[叮咚签到] 积分：" + str(aaa['data']['point'])+"连签："+str(aaa['data']['sign_series'])+"天")
        content = content + "\n" + "[叮咚签到] 积分：" + str(aaa['data']['point'])+"连签："+str(aaa['data']['sign_series'])+"天"
    else:
        print("[叮咚签到] 失败，查看输出日志查看原因")
        print(response.text)
        content = content + "\n" + "[叮咚签到] 失败，查看输出日志查看原因"

def 养鱼_取进度():
    url = 'https://farm.api.ddxq.mobi/api/v2/userguide/detail?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&app_version=9.40.0&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=1&guideCode=FISHPOND_NEW'
    response = requests.get(url=url,headers=headers)
    global content
    #print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[养鱼状态] 饲料：" + str(aaa['data']['feed']['amount']) + "  " + aaa['data']['baseSeed']['msg']
        print("[养鱼状态] 饲料：" + str(aaa['data']['feed']['amount']) + "  " + aaa['data']['baseSeed']['msg'])
        return aaa['data']['feed']['amount']
    else:
        content = content + "\n" + '[养鱼状态] 获取失败'
        print('[养鱼状态] 获取失败')
        return 0
    time.sleep(3)
def 养鱼_三餐领取():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/achieve?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&app_version=9.40.0&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=1&taskCode=LOTTERY'
    response = requests.get(url=url,headers=headers)
    global content
    #print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[养鱼三餐] " + str(aaa['data']['rewards'][0]['amount'])
        print("[养鱼三餐] " + str(aaa['data']['rewards'][0]['amount']))
    else:
        if response.text.find('任务尚未开启') != -1 or response.text.find('你已完成任务') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + '[养鱼三餐] ' + aaa['msg']
            print('[养鱼三餐] ' + aaa['msg'])
        else:
            content = content + "\n" + '[养鱼三餐] 获取失败'
            print('[养鱼三餐] 获取失败')
    time.sleep(3)
def 养鱼_投喂():
    coin = 养鱼_取进度()#取现存饲料，每天只留10g
    # times = int(coin/10-1)
    # print(f"[养鱼投喂] 投喂次数：{times}")
    for i in range(25):#余粮太多，每天会上限，限制25次
        url = 'https://farm.api.ddxq.mobi/api/v2/props/feed?api_version=9.1.0&app_client_id=2&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&app_version=9.56.0&OSVersion=7&CityId=1802&uid=617608be87371800019d291b&latitude=24.60854&longitude=118.103438&lat=24.60854&lng=118.103438&device_token=BCDHSomBsxCuhCkeSbk8nYpRq+iBOafh77+bvaipIgnnpGKZb3tdIX34xCwOfPi+U2OtxXQdh5G1la38+ib536w==&gameId=1&propsId=211028226650475027&seedId=220707099701270027&cityCode=1802&feedPro=0&triggerMultiFeed=1'
        response = requests.get(url=url,headers=headers)
        global content
        #print(response.text)
        if response.text.find('请求成功') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + "[养鱼投喂] 成功，剩余饲料：" + str(aaa['data']['feed']['amount'])
            print("[养鱼投喂] 成功，剩余饲料：" + str(aaa['data']['feed']['amount']))
        elif response.text.find('今天喂食太多了') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + "[养鱼投喂] 今天喂食太多了"
            print("[养鱼投喂] 今天喂食太多了")
        else:
            content = content + "\n" + '[养鱼投喂] 获取失败'
            #print(response.text)
            print('[养鱼投喂] 获取失败')
        time.sleep(3)
    time.sleep(3)
def 养鱼_签到():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/achieve?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&app_version=9.40.0&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=1&taskCode=DAILY_SIGN'
    response = requests.get(url=url,headers=headers)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[养鱼每日签到] " + str(aaa['data']['rewards'][0]['amount'])
        print("[养鱼每日签到] " + str(aaa['data']['rewards'][0]['amount']))
    else:
        if response.text.find('今日已完成任务') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + '[养鱼每日签到] ' + aaa['msg']
            print('[养鱼每日签到] ' + aaa['msg'])
        else:
            content = content + "\n" + '[养鱼每日签到] 获取失败'
            print('[养鱼每日签到] 获取失败')
    time.sleep(3)
def 养鱼_连续签到():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/achieve?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&app_version=9.40.0&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=1&taskCode=CONTINUOUS_SIGN'
    response = requests.get(url=url,headers=headers)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[养鱼连续签到] " + str(aaa['data']['rewards'][0]['amount'])
        print("[养鱼连续签到] " + str(aaa['data']['rewards'][0]['amount']))
    else:
        if response.text.find('今日已完成任务') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + '[养鱼连续签到] ' + aaa['msg']
            print('[养鱼连续签到] ' + aaa['msg'])
        else:
            content = content + "\n" + '[养鱼连续签到] 获取失败'
            print('[养鱼连续签到] 获取失败')
    time.sleep(3)
def 养鱼_领取下单任务():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/receive?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&app_version=9.40.0&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=1&taskCode=ANY_ORDER'
    response = requests.get(url=url,headers=headers)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[养鱼领取下单任务] " + aaa['data']['taskStatus']
        print("[养鱼领取下单任务] " + aaa['data']['taskStatus'])
    else:
        if response.text.find('今天已经领取过该任务了') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + '[养鱼领取下单任务] ' + aaa['msg']
            print('[养鱼领取下单任务] ' + aaa['msg'])
        else:
            content = content + "\n" + '[养鱼领取下单任务] 获取失败'
            print('[养鱼领取下单任务] 获取失败')
    time.sleep(3)
def 养鱼_翻牌():
    #只翻一次
    #翻牌
    url = 'https://farm.api.ddxq.mobi/api/v2/lucky-draw-activity/draw?api_version=9.7.3&app_version=1.0.0&app_client_id=3&station_id=60e26f9abd8d8c0001eca0e8&native_version=9.40.0&city_number=1802&latitude=24.608563&longitude=118.103879&gameId=1'
    headers1 = {"Host": "farm.api.ddxq.mobi",
               "Connection": "keep-alive",
               "Accept": "*/*",
               "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
               "Accept-Encoding": "gzip, deflate, br",
               "Accept-Language": "zh-CN",
               "Referer": "https://game.m.ddxq.mobi/index.html",
               "Origin": "https://game.m.ddxq.mobi",
               "Cookie": Cookie,
               "DDMC-GAME-TID":"1"
               }
    response = requests.get(url=url,headers=headers1)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[养鱼翻牌] " + aaa['data']['chosen']['rewardText']
        print("[养鱼翻牌] " + aaa['data']['chosen']['rewardText'])
    else:
        content = content + "\n" + '[养鱼翻牌] 获取失败'
        print('[养鱼翻牌] 获取失败')
    time.sleep(3)
def 养鱼_浏览商品():
    #浏览
    url = 'https://cms.api.ddxq.mobi/cms-service/client/page/v1/getPageInfo?uuid=797531e296f540d6&themeColor=72b1ff&hideShare=true&gameType=Farm&gameTask=BROWSE_GOODS&s=mine_farm_new&native_city_number=1802'
    headers1 = {"Host": "cms.api.ddxq.mobi",
               "Connection": "keep-alive",
               "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
               "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
               "Accept-Encoding": "gzip, deflate, br",
               "Accept-Language": "zh-CN",
               "Cookie": Cookie
               }
    response = requests.get(url=url,headers=headers1)
    # print(response.text)
    global content
    if response.text.find('鱼塘浏览商品奖励饲料啦') != -1:
        content = content + "\n" + "[养鱼浏览商品] 开始"
        print("[养鱼浏览商品] 开始")
    else:
        content = content + "\n" + '[养鱼浏览商品] 获取失败'
        print('[养鱼浏览商品] 获取失败')
    time.sleep(35)
    #提交浏览
    url = 'https://farm.api.ddxq.mobi/api/v2/task/achieve?latitude=0&longitude=0&env=PE&station_id=60e26f9abd8d8c0001eca0e8&city_number=1802&api_version=9.28.0&app_client_id=3&native_version=9.40.0&h5_source=&page_type=2&gameId=1&taskCode=BROWSE_GOODS&'
    headers1 = {"Host": "farm.api.ddxq.mobi",
                "Connection": "keep-alive",
                "Accept": "*/*",
                "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
                "Accept-Encoding": "gzip, deflate, br",
                "Accept-Language": "zh-CN",
                "Referer": "https://cms.api.ddxq.mobi/cms-service/client/page/v1/getPageInfo?uuid=797531e296f540d6&themeColor=72b1ff&hideShare=true&gameType=Farm&gameTask=BROWSE_GOODS&s=mine_farm_new&native_city_number=1802",
                "Origin": "https://cms.api.ddxq.mobi",
                "Cookie": Cookie,
                "DDMC-GAME-TID": "1"
                }
    response = requests.get(url=url, headers=headers1)
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[养鱼浏览商品] 提交" + aaa['data']['taskStatus']
        print("[养鱼浏览商品] 提交" + aaa['data']['taskStatus'])
    else:
        content = content + "\n" + '[养鱼浏览商品] 提交失败'
        print('[养鱼浏览商品] 提交失败')
    time.sleep(3)
def 养鱼_任务列表_领取():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/list?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&app_version=9.40.0&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=1&cityCode=1802'
    response = requests.get(url=url, headers=headers)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        i = 0
        for task in aaa['data']['userTasks']:
            # print(f"[种树任务列表] {i}" , aaa['data']['userTasks'][i]['taskName'],aaa['data']['userTasks'][i]['buttonStatus'],aaa['data']['userTasks'][i]['userTaskLogId'])
            if aaa['data']['userTasks'][i]['buttonStatus'] == "TO_REWARD" and aaa['data']['userTasks'][i]['userTaskLogId'] != None:  # 完成任务
                id = aaa['data']['userTasks'][i]['userTaskLogId']
                content = content + "\n" + "[养鱼任务列表] " + aaa['data']['userTasks'][i]['taskName'] + "完成,userTaskLogId:" + aaa['data']['userTasks'][i]['userTaskLogId']
                print("[养鱼任务列表] " + aaa['data']['userTasks'][i]['taskName'] + " 完成,userTaskLogId:",aaa['data']['userTasks'][i]['userTaskLogId'])
                # 领取
                url = f'https://farm.api.ddxq.mobi/api/v2/task/reward?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&app_version=9.40.0&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=1&userTaskLogId={id}'
                response = requests.get(url=url, headers=headers)
                # print(response.text)
                if response.text.find('请求成功') != -1:
                    bbb = json.loads(response.text)
                    content = content + "\n" + "[养鱼任务奖励领取] " + aaa['data']['userTasks'][i]['taskName'] + ": " + str(bbb['data']['rewards'][0]['amount'])
                    print("[养鱼任务奖励领取] " + aaa['data']['userTasks'][i]['taskName'] + ": " + str(bbb['data']['rewards'][0]['amount']))
                else:
                    if response.text.find('你已领取奖励') != -1:
                        bbb = json.loads(response.text)
                        content = content + "\n" + '[养鱼任务奖励领取] ' + bbb['msg']
                        print('[养鱼任务奖励领取] ' + bbb['msg'])
                    else:
                        content = content + "\n" + '[养鱼任务奖励领取] 获取失败'
                        print('[养鱼任务奖励领取] 获取失败')

            i = i + 1
    else:
        content = content + "\n" + '[养鱼任务列表] 获取失败'
        print('[养鱼任务列表] 获取失败')
    time.sleep(3)
def 种树_取进度():
    url = 'https://farm.api.ddxq.mobi/api/v2/userguide/orchard/detail?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&uid=617608be87371800019d291b&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=2&cityCode=1802'
    response = requests.get(url=url,headers=headers2)
    global content
    #print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[种树状态] 饲料：" + str(aaa['data']['feed']['amount']) + "  " + aaa['data']['baseSeed']['msg']
        print("[种树状态] 饲料：" + str(aaa['data']['feed']['amount']) + "  " + aaa['data']['baseSeed']['msg'])
        return aaa['data']['feed']['amount']
    else:
        content = content + "\n" + '[种树状态] 获取失败'
        print('[种树状态] 获取失败')
        return 0
    time.sleep(3)
def 种树_三餐领取():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/achieve?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&uid=617608be87371800019d291b&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&taskCode=LOTTERY'
    response = requests.get(url=url,headers=headers2)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[种树三餐] " + str(aaa['data']['rewards'][0]['amount'])
        print("[种树三餐] " + str(aaa['data']['rewards'][0]['amount']))
    else:
        if response.text.find('任务尚未开启') != -1 or response.text.find('你已完成任务') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + '[种树三餐] ' + aaa['msg']
            print('[种树三餐] ' + aaa['msg'])
        else:
            content = content + "\n" + '[种树三餐] 获取失败'
            print('[种树三餐] 获取失败')
    time.sleep(3)
def 种树_浇水():
    coin = 种树_取进度()#取现存饲料，每天只留10g
    times = int(coin/10)
    print(f"[种树浇水] 浇水次数：{times}")
    for i in range(times):
        url = 'https://farm.api.ddxq.mobi/api/v2/props/feed?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&CityId=1802&OSVersion=14&uid=617608be87371800019d291b&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&device_token=BkX+e39jzylm0ASF5DrNdTYc6fd9EqHg5ep7F4hlyXFtm6TWfHhvcgBxhQK4VAWvWehfixts1ypbIkPZRtfIHoQ==&propsCode=FEED&seedId=220210217378793027&propsId=211112087651826027'
        response = requests.get(url=url,headers=headers2)
        global content
        #print(response.text)
        if response.text.find('请求成功') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + "[种树浇水] 成功，剩余饲料：" + str(aaa['data']['feed']['amount'])
            print("[种树浇水] 成功，剩余饲料：" + str(aaa['data']['feed']['amount']))
        else:
            content = content + "\n" + '[种树浇水] 获取失败'
            print('[种树浇水] 获取失败')
            print(response.text)
        time.sleep(3)
    time.sleep(3)
def 种树_领取下单任务():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/receive?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&uid=617608be87371800019d291b&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&gameId=2&taskCode=ANY_ORDER'
    response = requests.get(url=url,headers=headers2)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[种树领取下单任务] " + aaa['data']['taskStatus']
        print("[种树领取下单任务] " + aaa['data']['taskStatus'])
    else:
        if response.text.find('今天已经领取过该任务了') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + '[种树领取下单任务] ' + aaa['msg']
            print('[种树领取下单任务] ' + aaa['msg'])
        else:
            content = content + "\n" + '[种树领取下单任务] 获取失败'
            print('[种树领取下单任务] 获取失败')
    time.sleep(3)
def 种树_签到():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/achieve?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&uid=617608be87371800019d291b&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&taskCode=DAILY_SIGN'
    response = requests.get(url=url, headers=headers2)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[种树每日签到] " + str(aaa['data']['rewards'][0]['amount'])
        print("[种树每日签到] " + str(aaa['data']['rewards'][0]['amount']))
    else:
        if response.text.find('今日已完成任务') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + '[种树每日签到] ' + aaa['msg']
            print('[种树每日签到] ' + aaa['msg'])
        else:
            content = content + "\n" + '[种树每日签到] 获取失败'
            print('[种树每日签到] 获取失败')
    time.sleep(3)
def 种树_连续签到():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/achieve?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&uid=617608be87371800019d291b&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&taskCode=CONTINUOUS_SIGN'
    response = requests.get(url=url, headers=headers2)
    global content
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[种树连续签到] " + str(aaa['data']['rewards'][0]['amount'])
        print("[种树连续签到] " + str(aaa['data']['rewards'][0]['amount']))
    else:
        if response.text.find('今日已完成任务') != -1:
            aaa = json.loads(response.text)
            content = content + "\n" + '[种树连续签到] ' + aaa['msg']
            print('[种树连续签到] ' + aaa['msg'])
        else:
            content = content + "\n" + '[种树连续签到] 获取失败'
            print('[种树连续签到] 获取失败')
    time.sleep(3)
def 种树_任务列表_领取():
    url = 'https://farm.api.ddxq.mobi/api/v2/task/list-orchard?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&uid=617608be87371800019d291b&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&reward=FEED&cityCode=1802'
    response = requests.get(url=url, headers=headers2)
    global content
    #print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        i = 0
        for task in aaa['data']['userTasks']:
            #content = content + "\n" + "[种树任务列表] " + aaa['data']['userTasks'][i]['taskName']
            # print(f"[种树任务列表] {i}" , aaa['data']['userTasks'][i]['taskName'],aaa['data']['userTasks'][i]['buttonStatus'],aaa['data']['userTasks'][i]['userTaskLogId'])
            if aaa['data']['userTasks'][i]['buttonStatus'] == "TO_REWARD" and aaa['data']['userTasks'][i]['userTaskLogId'] != None :#完成任务
                id = aaa['data']['userTasks'][i]['userTaskLogId']
                content = content + "\n" + "[种树任务列表] " + aaa['data']['userTasks'][i]['taskName'] + "完成,userTaskLogId:" + aaa['data']['userTasks'][i]['userTaskLogId']
                print("[种树任务列表] " + aaa['data']['userTasks'][i]['taskName'] + " 完成,userTaskLogId:",aaa['data']['userTasks'][i]['userTaskLogId'])
                # 领取
                url = f'https://farm.api.ddxq.mobi/api/v2/task/reward?api_version=9.1.0&app_client_id=1&station_id=60e26f9abd8d8c0001eca0e8&stationId=60e26f9abd8d8c0001eca0e8&native_version=&uid=617608be87371800019d291b&latitude=24.608563&longitude=118.103879&lat=24.608563&lng=118.103879&userTaskLogId={id}'
                response = requests.get(url=url, headers=headers2)
                #print(response.text)
                if response.text.find('请求成功') != -1:
                    bbb = json.loads(response.text)
                    content = content + "\n" + "[种树任务奖励领取] " + aaa['data']['userTasks'][i]['taskName'] + ": " + str(bbb['data']['rewards'][0]['amount'])
                    print("[种树任务奖励领取] " + aaa['data']['userTasks'][i]['taskName'] + ": " + str(bbb['data']['rewards'][0]['amount']))
                else:
                    if response.text.find('你已领取奖励') != -1:
                        bbb = json.loads(response.text)
                        content = content + "\n" + '[种树任务奖励领取] ' + bbb['msg']
                        print('[种树任务奖励领取] ' + bbb['msg'])
                    else:
                        content = content + "\n" + '[种树任务奖励领取] 获取失败'
                        print('[种树任务奖励领取] 获取失败')

            i=i+1
    else:
        content = content + "\n" + '[养鱼任务列表] 获取失败'
        print('[养鱼任务列表] 获取失败')
    time.sleep(3)
def 种树_浏览商品():
    #浏览
    url = 'https://cms.api.ddxq.mobi/cms-service/client/page/v1/getPageInfo?uuid=8bda32e7c4b8432e&themeColor=e7fbd6&hideShare=true&gameTask=BROWSE_GOODS&s=farm&native_city_number=1802'
    headers1 = {"Host": "cms.api.ddxq.mobi",
               "Connection": "keep-alive",
               "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
               "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
               "Accept-Encoding": "gzip, deflate, br",
               "Accept-Language": "zh-CN",
               "Cookie": Cookie
               }
    response = requests.get(url=url,headers=headers1)
    # print(response.text)
    global content
    if response.text.find('果园浏览商品奖励水滴啦') != -1:
        content = content + "\n" + "[种树浏览商品] 开始"
        print("[种树浏览商品] 开始")
    else:
        content = content + "\n" + '[种树浏览商品] 获取失败'
        print('[种树浏览商品] 获取失败')
    time.sleep(35)
    #提交浏览
    url = 'https://farm.api.ddxq.mobi/api/v2/task/achieve?latitude=24.608563&longitude=118.103879&env=PE&station_id=60e26f9abd8d8c0001eca0e8&city_number=1802&api_version=9.28.0&app_client_id=3&native_version=9.40.0&h5_source=&page_type=2&gameId=2&taskCode=BROWSE_GOODS&'
    headers1 = {"Host": "farm.api.ddxq.mobi",
                "Connection": "keep-alive",
                "Accept": "*/*",
                "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
                "Accept-Encoding": "gzip, deflate, br",
                "Accept-Language": "zh-CN",
                "Referer": "https://cms.api.ddxq.mobi/cms-service/client/page/v1/getPageInfo?uuid=8bda32e7c4b8432e&themeColor=e7fbd6&hideShare=true&gameTask=BROWSE_GOODS&s=farm&native_city_number=1802",
                "Origin": "https://cms.api.ddxq.mobi",
                "Cookie": Cookie,
                "DDMC-GAME-TID": "2"
                }
    response = requests.get(url=url, headers=headers1)
    # print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        content = content + "\n" + "[种树浏览商品] 提交" + aaa['data']['taskStatus']
        print("[种树浏览商品] 提交" + aaa['data']['taskStatus'])
    else:
        content = content + "\n" + '[种树浏览商品] 提交失败'
        print('[种树浏览商品] 提交失败')
    time.sleep(3)

def 待评价列表_评价():
    url = 'https://maicai.api.ddxq.mobi/order/evaluateList'
    headers3 = {"Host": "maicai.api.ddxq.mobi",
                "Connection": "keep-alive",
                "Content-Length": "549",
                "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
                "Accept-Encoding": "gzip, deflate, br",
                "content-type": "application/x-www-form-urlencoded",
                "Referer": "https://servicewechat.com/wx1e113254eda17715/382/page-frame.html",
                "Cookie": Cookie,
                }
    body = "uid=617608be87371800019d291b&longitude=118.102121&latitude=24.573598&station_id=61089ecefb921b0001fbd706&city_number=1802&api_version=9.41.0&app_version=2.70.11&applet_source=&channel=applet&app_client_id=4&sharer_uid=&s_id=aface2ef53742cd00d27edb407ed341b&openid=osP8I0RyceSzHujn39d_1_OksrCE&h5_source=&device_token=WHJMrwNw1k%2FEIUPmApmIP5BwabsMIQxnywBTuPTTDxIi8GkrYcjkKBgoiDgra047nNEFW7USp905oCCKMo3pWupGHP%2Fm4okf2dCW1tldyDzmauSxIJm5Txg%3D%3D1487582755342&page=1&nars=7a8eb74e85436205d51211cbe38858ce&sesi=TpiFQMEa75f527355e4a71fd8fa8645c9a2eae0"
    response = requests.post(url=url, headers=headers3,data =body)
    global content
    #print(response.text)

    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        i = 0
        print("待评价订单数量："+str (len(aaa['data']['order_list'])))
        for order in aaa['data']['order_list']:
            j=0
            print(f"第{i+1}个订单商品数量：" + str(len(aaa['data']['order_list'][i]['product'])) + "订单编号：" + aaa['data']['order_list'][i]['order_number'])
            order = aaa['data']['order_list'][i]['order_number']
            params = []
            for product in aaa['data']['order_list'][i]['product']:
                bbb= aaa['data']['order_list'][i]['product']
                print(bbb[j]['product_name'],bbb[j]['id'])
                name = bbb[j]['product_name']  # 菜名
                no = bbb[j]['id']  # id
                temp = {'img_url': [],
                        'id': no,
                        'name': name,
                        'eval_content': "挺新鲜的，东西还不错。",  # 评论内容
                        'eval_star': 5,
                        'comment_type': "2",
                        'label': {}
                        }
                # print(temp)
                params.append(temp)
                j=j+1
            k = str(params)  # 转为文本
            k = k.replace(" ", "")  # 去掉空格
            k=parse.quote_plus(k)  # url编码,只需要编码这部分，其他的不编码
            body = f"uid=617608be87371800019d291b&longitude=118.102121&latitude=24.573598&station_id=61089ecefb921b0001fbd706&city_number=1802&api_version=9.41.0&app_version=2.70.11&applet_source=&channel=applet&app_client_id=4&sharer_uid=&s_id=fe5a718dec3fa6a3569505453493794e&openid=osP8I0RyceSzHujn39d_1_OksrCE&h5_source=&device_token=WHJMrwNw1k/EIUPmApmIP5BwabsMIQxnywBTuPTTDxIi8GkrYcjkKBgoiDgra047nNEFW7USp905oCCKMo3pWupGHP/m4okf2dCW1tldyDzmauSxIJm5Txg==1487582755342&order_number={order}&params={k}&nars=f4b8b887dbf3b7d7a53d9afaf98f1fa0&sesi=UvebDA2104fc06602984c463b3701ea3a571b18"
            # print(body)
            # body = parse.quote_plus(body)  # url编码
            # print(body)
            url = 'https://maicai.api.ddxq.mobi/comment/add' #评价
            headers3 = {"Host": "maicai.api.ddxq.mobi",
                        "Connection": "keep-alive",
                        "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.40.0 station_id/60e26f9abd8d8c0001eca0e8",
                        "Accept-Encoding": "gzip, deflate, br",
                        "content-type": "application/x-www-form-urlencoded",
                        "Referer": "https://servicewechat.com/wx1e113254eda17715/382/page-frame.html",
                        "Cookie": Cookie,
                        }
            response = requests.post(url=url, headers=headers3, data=body)
            if response.text.find('请求成功') != -1:
                print(response.text)
                aaa = json.loads(response.text)
                content = content + "\n" + '[订单评价奖励] ' + str(aaa['data']['point'])
                print('[订单评价奖励] ' + str(aaa['data']['point']))
            else:
                print(response.text)
                content = content + "\n" + '[订单评价奖励] 失败'
                print('[订单评价奖励] 失败')
            i=i+1
    else:
        content = content + "\n" + '[待评价列表] 获取失败'
        print('[待评价列表] 获取失败')

def 种树_施肥():
    # 取肥料肥力
    url = 'https://farm.api.ddxq.mobi/api/v2/task/list-orchard?api_version=9.1.0&app_client_id=1&station_id=6114968293bf0e000142f465&stationId=6114968293bf0e000142f465&native_version=&CityId=1802&OSVersion=14&uid=617608be87371800019d291b&latitude=24.523917&longitude=118.118025&lat=24.523917&lng=118.118025&reward=FERTILIZER&cityCode=1802'
    response = requests.get(url=url, headers=headers2)
    #print(response.text)
    if response.text.find('请求成功') != -1:
        aaa = json.loads(response.text)
        #content = content + "\n" + "[种树施肥次数] 成功，" + str(aaa['data']['propsUseResultVo']['amount'])
        times = (100 - aaa['data']['fertilizerUse']['amount'])/10 #需施肥次数
        print("[种树肥力] " + str(aaa['data']['fertilizerUse']['amount']),"需施肥次数：",int(times))
        global content
        for i in range(int(times)):#施肥
            url = 'https://farm.api.ddxq.mobi/api/v2/props/props-use?api_version=9.1.0&app_client_id=1&station_id=6114968293bf0e000142f465&stationId=6114968293bf0e000142f465&native_version=&CityId=1802&OSVersion=14&uid=617608be87371800019d291b&latitude=24.523917&longitude=118.118025&lat=24.523917&lng=118.118025&propsCode=FERTILIZER&propsId=211112087651840027&seedId=211112087651813027'
            response = requests.get(url=url,headers=headers2)
            #print(response.text)
            if response.text.find('请求成功') != -1:
                aaa = json.loads(response.text)
                content = content + "\n" + f"[种树施肥{i+1}] 成功，" + str(aaa['data']['propsUseResultVo']['amount'])
                print(f"[种树施肥{i+1}] 成功，" + str(aaa['data']['propsUseResultVo']['amount']))
            else:
                content = content + "\n" + f"[种树施肥{i+1}] 获取失败"
                print(f"[种树施肥{i+1}] 获取失败")
                print(response.text)
            time.sleep(3)
        time.sleep(3)
    else:
        #content = content + "\n" + "[种树施肥次数] 获取失败"
        print("[种树肥力] 获取失败")
        print(response.text)


hour = time.localtime().tm_hour
# print(hour,time.localtime())
if hour == 8:  # 每天7-9点,10-12,16-18三餐
    养鱼_签到()# X
    养鱼_三餐领取()# X
    养鱼_连续签到()# X
    养鱼_领取下单任务()
    养鱼_翻牌()
    养鱼_浏览商品()# X 提交失败
    养鱼_任务列表_领取()
    养鱼_投喂()
    养鱼_取进度()

     种树_签到()
     种树_三餐领取()
     种树_连续签到()
     种树_浏览商品()
     种树_领取下单任务()
     种树_任务列表_领取()
     种树_浇水()
     种树_取进度()
elif hour == 11 or hour == 17:
     养鱼_三餐领取()
     种树_三餐领取()
elif hour == 23:
     养鱼_任务列表_领取()#领取下单任务的奖励
     种树_任务列表_领取()#领取下单任务的奖励
     待评价列表_评价()

content = parse.quote_plus(content)#url编码
title = parse.quote_plus('叮咚')#url编码
requests.get(f'http://www.pushplus.plus/send?token={p_token}&title={title}&content={content}')





# uid=617608be87371800019d291b&longitude=118.102121&latitude=24.573598&station_id=61089ecefb921b0001fbd706&city_number=1802&api_version=9.41.0&app_version=2.70.11&applet_source=&channel=applet&app_client_id=4&sharer_uid=&s_id=fe5a718dec3fa6a3569505453493794e&openid=osP8I0RyceSzHujn39d_1_OksrCE&h5_source=&device_token=WHJMrwNw1k/EIUPmApmIP5BwabsMIQxnywBTuPTTDxIi8GkrYcjkKBgoiDgra047nNEFW7USp905oCCKMo3pWupGHP/m4okf2dCW1tldyDzmauSxIJm5Txg==1487582755342&order_number=2112033954551869603&params=[{"img_url":[],"id":"604982db439ac042bf60eb01","name":"荷兰豆 约200g","eval_content":"挺新鲜的，东西还不错。","eval_star":5,"comment_type":"2","label":{}},{"img_url":[],"id":"58b7ccdd936edf38323cc16a","name":"爆汁番茄 约500g","eval_content":"挺新鲜的，东西还不错。","eval_star":5,"comment_type":"2","label":{}},{"img_url":[],"id":"5e47d66e7cdbf0131972efc4","name":"鲜活对虾  250g（1-2人食）","eval_content":"挺新鲜的，东西还不错。","eval_star":5,"comment_type":"2","label":{}},{"img_url":[],"id":"60a3ba8f5b3a8468f76c52e0","name":"冰鲜海蛎肉 170g以上","eval_content":"挺新鲜的，东西还不错。","eval_star":5,"comment_type":"2","label":{}},{"img_url":[],"id":"5dea0b1510abf10ec4336341","name":"黄粒玉米 约350g","eval_content":"挺新鲜的，东西还不错。","eval_star":5,"comment_type":"2","label":{}},{"img_url":[],"id":"5e9448aabdb365338d68b186","name":"鸡毛菜  约250g","eval_content":"挺新鲜的，东西还不错。","eval_star":5,"comment_type":"2","label":{}},{"img_url":[],"id":"5dc4d2ba7cdbf0131a0e62db","name":"精品蟹味菇 150g","eval_content":"挺新鲜的，东西还不错。","eval_star":5,"comment_type":"2","label":{}},{"id":"60dd96424ef0eb983d930171","name":"叮咚买菜","eval_content":"","label":{},"eval_star":"5","comment_type":"1"}]&nars=f4b8b887dbf3b7d7a53d9afaf98f1fa0&sesi=UvebDA2104fc06602984c463b3701ea3a571b18

#拼接json后拼接body在URL编码，返回以下内容
#{"msg":"请求成功","code":0,"timestamp":"2021-12-04 09:59:46","success":true,"data":{"message":"感谢您的支持和反馈，我们会继续努力给您带来更好的购物体验。","img":"","title":"","point":19,"need_market_evaluate":false,"market_info":{},"ad_info":{"ads":[{"link":"/pages/giftEarn/giftEarn","image":"https://ddfs-public.ddimg.mobi/compass-admin/gif/2021/11/24/94a34463c30e4a9886c263299aeceb92.gif?width=1035&height=420","width":1035,"height":420,"id":"619e0215335c940001ef670e","name":"邀请有礼评价页好评广告59-40（送大虾）新版2.0","content":"","image_2":"","width_2":null,"height_2":null,"recipe_mark":0}],"id":2004,"name":"好评完成_邀请邻友59-40元_新版2.0【11.26】大虾","width":1035,"height":420,"_id":"619f925124bfea00010a2a9d","finish_time":1672415999,"start_time":1637856000},"order_type":100007,"is_good_comment":true},"requestValue":{},"exec_time":null}


# for i in range(9):
#     name = f"菜名_{i+1}"#改成菜名
#     no = f"20211203_{i+1}"#改成id
#     temp ={'img_url':[],
#            'id':no,
#            'name': name,
#            'eval_content': "挺新鲜的，东西还不错。",#评论内容
#            'eval_star': 5,
#            'comment_type': "2",
#            'label':{}
#             }
#     # print(temp)
#     params.append(temp)
# k = str(params)#转为文本
# k = k.replace(" ","")#去掉空格
# order = "2112033954551869603"
# body = f"uid=617608be87371800019d291b&longitude=118.102121&latitude=24.573598&station_id=61089ecefb921b0001fbd706&city_number=1802&api_version=9.41.0&app_version=2.70.11&applet_source=&channel=applet&app_client_id=4&sharer_uid=&s_id=fe5a718dec3fa6a3569505453493794e&openid=osP8I0RyceSzHujn39d_1_OksrCE&h5_source=&device_token=WHJMrwNw1k/EIUPmApmIP5BwabsMIQxnywBTuPTTDxIi8GkrYcjkKBgoiDgra047nNEFW7USp905oCCKMo3pWupGHP/m4okf2dCW1tldyDzmauSxIJm5Txg==1487582755342&order_number={order}&params={k}&nars=f4b8b887dbf3b7d7a53d9afaf98f1fa0&sesi=UvebDA2104fc06602984c463b3701ea3a571b18"
# body = parse.quote_plus(body)#url编码
# print(body)



